package org.kirhgoff.mathbot;

import org.aicontest.Planet;

public class PlanetInfo {
	private int allowedForce = 0; //amount of ships planet is ready to send
	private int population;
	private double x;
	private double y;
	private int owner;
	private int growthRate;
	private int id;
	private boolean coveredByAttack = false;
	
	public PlanetInfo(Planet planet) {
		x = planet.X();
		y = planet.Y();
		population = planet.NumShips();
		growthRate = planet.GrowthRate();
		id = planet.PlanetID(); //??? but seems thats how it works
		owner = planet.Owner();
	}

	public void sendShips(Planet target, int shipsToSend) {
		if (allowedForce < shipsToSend) {
			throw new RuntimeException("Cannot send more than have");
		}
		allowedForce -= shipsToSend;
	}

	public int force() {
		return allowedForce;
	}

	public void setForce(int force) {
		if (force < 0) throw new RuntimeException ("Cannot have force below 0, was " + force);
		this.allowedForce = force;
	}

	public double x() {
		return x;
	}

	public double y() {
		return y;
	}

	public int population() {
		return population;
	}

	public void setPopulation(int population) {
		if (population < 0) throw new RuntimeException ("Cannot have population below 0");
		this.population = population;
	}

	public boolean isMine() {
		return owner == World.OWNER_ME;
	}
	
	public int owner () {
		return owner;
	}

	public int growthRate() {
		return growthRate;
	}

	public int id() {
		return id;
	}
	
	@Override
	public String toString() {
		return "Planet: id=" + id () + " owner=" + World.name(owner ()) +
				" force=" + allowedForce +
				" x/y=[" + x () + ", " + y () + "]" +
				" p/g=(" + population() + "/" + growthRate() + ") covered=" + coveredByAttack;  
	}

	public void setCoveredByAttack(boolean covered) {
		coveredByAttack = covered;
	}
	
	public boolean coveredByAttack () {
		return coveredByAttack;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof PlanetInfo)) {
			return false;
		}
		PlanetInfo another = (PlanetInfo) obj;
		return id () == another.id ();
	}
	
	@Override
	public int hashCode() {
		return id();
	}

}
